package com.bbs.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bbs.mapper.AdminMapper;
import com.bbs.pojo.Admin;
import com.bbs.pojo.AdminInfo;
import com.bbs.pojo.PostType;
import com.bbs.pojo.User;

@Service
public class AdminServiceImpl implements AdminService {
	@Autowired
	private AdminMapper adminMapper;

	// 管理员登录
	public Admin login(String username, String password) {
		return adminMapper.login(username, password);
	}

	// 查询所有用户
	@Override
	public List<User> findUserAll() {
		return adminMapper.findUserAll();
	}

	// 查询所有管理员
	@Override
	public List<Admin> findAdminAll() {
		return adminMapper.findAdminAll();
	}

	// 查询所有管理员详情
	@Override
	public List<AdminInfo> findAdminInfoAll() {
		return adminMapper.findAdminInfoAll();
	}

	// 通过用户名查询管理员
	@Override
	public List<AdminInfo> selectAdminInfoByUserName(String username) {

		return adminMapper.selectAdminInfoByUserName(username);
	}

	// 通过用户名查询用户
	@Override
	public List<User> selectUserByUserName(String username) {

		return adminMapper.selectUserByUserName(username);
	}
	
	// 查询所有post类型
	@Override
	public List<PostType> selectTypeAll() {
		
		return adminMapper.selectTypeAll();
	}

	//添加分类
	@Override
	public void addType(String postType) {
		// TODO Auto-generated method stub
		List<PostType>list=adminMapper.selectTypeAll();
		for(PostType type:list){
			
			if(type.getType().equals(postType)){
				return;
			}
		}
		adminMapper.addType(postType);
		
	}
	/*
	 * 删除分类
	 */
	@Override
	public void deleteType(String type) {
		// TODO Auto-generated method stub
		adminMapper.deleteType(type);
	}
	
	/*
	 * 根据类型删除
	 */
	@Override
	public void deletePostType(String type) {
		// TODO Auto-generated method stub
		adminMapper.deletePostType(type);
	}
	
	//根据用户id删除用户
	@Override
	public void deleteUserById(String id) {
		adminMapper.deleteUserById(id);
	}

}
